//
//  MyShowData.m
//  BosidengIphone
//
//  Created by  on 12-1-14.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "MyShowData.h"
#import "AppDelegate.h"

@implementation MyShowData
@synthesize showID;
@synthesize smallImage;
@synthesize bigImage;
@synthesize customerID;
@synthesize nickname;
@synthesize views;
@synthesize votings;
@synthesize isRecommend;
@synthesize createDate;
@synthesize modifyDate;
@synthesize showStatus;
@synthesize alreadyView;

- (id)init {
    if (self = [super init]) {
        
    }
    return self;
}

- (void)dealloc {
    [isRecommend release];
    [createDate release];
    [modifyDate release];
    [showStatus release];
    [showID release];
    [smallImage release];
    [bigImage release];
    [customerID release];
    [nickname release];
    [views release];
    [votings release];
    [super dealloc];
}

+ (id)getItemByID:(NSString *)uid {
    return [MyShowData findFirstByCriteria:[NSString stringWithFormat:@"WHERE show_i_d='%@'", uid]];
}

+ (NSArray *)getAllItems {
    return [MyShowData findByCriteria:@"WHERE show_status='1' ORDER BY modify_date DESC"];
}

+ (NSArray *)getRecommendItems {
    return [MyShowData findByCriteria:@"WHERE is_recommend='true' AND show_status='1' ORDER BY modify_date DESC"];
}

+ (NSArray *)getItemsByCustomerId:(NSString *)customerId {
    return [MyShowData findByCriteria:[NSString stringWithFormat:@"WHERE customer_i_d='%@' ORDER BY modify_date DESC", customerId]];
}

- (NSString *)description {
    return [NSString stringWithFormat:@"MyShow Item.%d, showID=%@", [self pk], showID];
}

- (void)setValue:(NSDictionary *)data {
    [super setValue:data];
    self.showID = [data objectForKey:@"ShowID"];
    self.smallImage = [data objectForKey:@"SmallImage"];
    self.bigImage = [data objectForKey:@"BigImage"];
    self.customerID = [data objectForKey:@"CustomerID"];
    self.nickname = [data objectForKey:@"Nickname"];
    self.views = [data objectForKey:@"Views"];
    self.votings = [data objectForKey:@"Votings"];
    self.isRecommend = [data objectForKey:@"IsRecommend"];
    self.createDate = [data objectForKey:@"CreateDate"];
    self.modifyDate = [data objectForKey:@"ModifyDate"];
    self.showStatus = [data objectForKey:@"ShowStatus"];
}

- (void)removeSmallImage {
    NSString *imagePath = [AppDelegate getCacheFilePathByUrl:smallImage];
    [AppDelegate deleteFile:imagePath];
}

- (void)removeBigImage {
    NSString *imagePath = [AppDelegate getCacheFilePathByUrl:bigImage];
    [AppDelegate deleteFile:imagePath];
}

- (void)removeLocalImages {
    [self removeSmallImage];
    [self removeBigImage];
}

@end
